<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--{include file='comm/header.tpl'}-->
    <!--{if $operFlg == 1}-->
    <title>会员等级添加</title>
    <!--{else}-->
    <title>会员等级编辑</title>
    <!--{/if}-->
</head>
<body>
	<div style="width:100%">
		
		<div class="items clearfix">
			
			<h2 style="" class="tal">
				<!--{if $operFlg == 1}-->
			    	会员等级添加
			    <!--{else}-->
			    	会员等级编辑
			    <!--{/if}-->
			</h2>
			
			<div class="items2">
				
				<form id="addForm" name="addForm" onsubmit="return false;">
					<table>
						<tr>
							<td width="150" class="tar">等级名称：</td>
							<td width="*" class="td_input" >
								<input type="text" style="width:200px" name="rankName" value="<!--{$rank_array.rankName|default:''}-->">
								<input type="hidden" name="rankID" value="<!--{$rank_array.rankID|default:0}-->">
                                <span class="red">*</span>
							</td>
						</tr>
						<tr>
							<td class="tar">累计消费金额：</td>
							<td class="td_input">
								<input type="text" style="width:200px" name="needAmt" value="<!--{$rank_array.needAmt|default:''}-->">
                                <span class="red">*</span>
                            </td>
						</tr>
						<tr>
							<td class="tar">价格折扣：</td>
							<td class="td_input">
								<input type="text" style="width:200px" name="rate" value="<!--{$rank_array.rate|default:''}-->">
                                <span class="red">*</span>
							</td>
						</tr>
						<tr>
							<td class="tar">赠送积分倍数：</td>
							<td class="td_input">
								<input type="text" style="width:200px" name="pointsRate" value="<!--{$rank_array.pointsRate|default:''}-->">
                                <span class="red">*</span>
                            </td>
						</tr>
						<tr>
							<td class="tar">折扣标识：</td>
							<td>
								<!--{if isset($rank_array) && $rank_array.discount_flg == 2}-->
									<input type="radio" name="discount_flg" value="1">&nbsp;销售价&nbsp;
									<input type="radio" name="discount_flg" value="2" checked="checked">&nbsp;市场价
								<!--{else}-->
									<input type="radio" name="discount_flg" value="1" checked="checked">&nbsp;销售价&nbsp;
									<input type="radio" name="discount_flg" value="2">&nbsp;市场价
								<!--{/if}-->
                                <span class="red">*</span>
							</td>
						</tr>
						<tr>
							<td class="tar">是否免运费：</td>
							<td>
								<!--{if isset($rank_array) && $rank_array.freightFree == 1}-->
									<input type="radio" name="freightFree" value="0">&nbsp;有运费&nbsp;
									<input type="radio" name="freightFree" value="1" checked="checked">&nbsp;免运费
								<!--{else}-->
									<input type="radio" name="freightFree" value="0" checked="checked">&nbsp;有运费&nbsp;
									<input type="radio" name="freightFree" value="1">&nbsp;免运费
								<!--{/if}-->
                                <span class="red">*</span>
							</td>
						</tr>

					</table>
				</form>

			</div>
			
		</div>
		
		<div class="bottom_fixbox">
			<div class="rectbox tac">
                <input type="button" class="btn" onclick="rank.check();" value="保存">
				<input type="button" class="btn" onclick="E.closeWindows();" value="关闭">
	        </div>
		</div>

	</div>

<script type="text/javascript">

    var rank = {

        dt: '',

        rankID: <!--{$rank_array.rankID|default:0}-->,

        //检测是否填写表单
        check: function() {

            this.dt = E.getFormValues('addForm');
            var error_msg = '';

            if (E.isEmpty(this.dt.rankName)){
                error_msg += '等级名称不能为空<br/>';
            }
            if (!E.isInt(this.dt.needAmt) || this.dt.needAmt < 0) {
                error_msg += '累计消费金额必须为大于等于0的整数<br/>';
            }
            if(!E.isNum(this.dt.rate) || this.dt.rate <= 0 || this.dt.rate > 1){
                error_msg += '价格折扣必须为大于0，小于等于1的数字<br/>';
            }
            if(!E.isNum(this.dt.pointsRate) || this.dt.pointsRate <= 0){
                error_msg += '赠送积分倍数必须为大于0的数字<br/>';
            }
            if (error_msg != '') {
                E.alert( error_msg );
            } else {
                E.confirm('您确认要保存该会员等级吗？', 'rank.edit');
            }

        },

        edit: function() {

            E.ajax_post({
                url: '/invokingAjax-backend/customer/customerRank.ajax?operFlg=2',
                data: this.dt,
                call: 'rank.result'
            });

        },

        result: function( o ) {

            if (o.code == 200) {
                E.opener('source.load');
                if (this.rankID == 0) {
                    E.alert(o.message,  2, "E.refresh");
                } else {
                    E.alert(o.message,  2, "E.closeWindows");
                }
            } else {
                E.alert(o.message);
            }

        }

    };

</script>

</body>
</html>